<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>客户端演示-1</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">客户端演示-1</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;">登录客户端</a>
        <dl class="layui-nav-child" id="clientId">

        </dl>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;">
          <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">
          <span id="username"></span>
        </a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:void(0);">个人信息</a></dd>
          <dd id="resetbtn"><a  href="/reset" >修改密码</a></dd>
          <dd><a href="/logout" id="logout">退出</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>

  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test" id="menuid">
<!--              //菜单管理列表-->

      </ul>
    </div>
  </div>

  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">通用安全组件演示</div>
  </div>

  <div class="layui-footer">
    <!-- 底部固定区域 -->
    底部固定区域
  </div>
</div>
</body>
</html>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.6.0.min.js" ></script>
<script src="/js/jq-cookie-1.1.js" ></script>
<script>

  /**************前端环境配置****************/


  // 产业UAT环境
  //var host_proc="http://spring-sso-client1-demo.chanyan-commonsafty-hantele:9001"
  // 测试环境
  //var host_proc="http://client.com:9001"
  // var host_proc="http://192.168.20.27:9001"
  //var host_proc="http://192.168.108.19:9002"
  // 本地环境
  // var host_proc="http://127.0.0.1:9001"
   var host_proc="http://client.com:9001"


  // -------------退出环境配置---------------
  //测试环境/opt/app/other环境
  //var logout_url="http://192.168.108.19:9096/logout"
  //测试环境
  var logout_url="http://183.235.210.8/logout"




  /**************前端环境配置****************/

  function render(){
    layui.use(['element', 'layer', 'util'], function(){
      var element = layui.element
              ,layer = layui.layer
              ,util = layui.util
              ,$ = layui.$;

      element.init();
    });
  }
  //spring-sso-client1-demo.chanyan-commonsafty-hantele:9001



  function logout(){
    $.ajax({
      url: logout_url,
      type: 'GET',
      headers: {
        "token": token
      },
      success: function (data) {
        console.log(data);
      },
      error: function (data) {
        console.log(data)
      }
    });
  }


$("#logout").click(function (){
  //logout();
 })



  // 获取用户基本信息
  function get_user_info(){

    $.ajax({
      url: host_proc+"/user/info",
      type: 'GET',
      headers: {
        "token": token
      },
      success: function (data) {
        $("#username").text(data["userName"]);
        client_template="<dd><a href=\"\">"+data["clientId"]+"</a></dd>";
        $("#clientId").html(client_template);
        //$("#logout").attr("href",logout_url+"?cid="+data["clientId"]);
        // $("#resetlink").attr("href","/reset?u="+data["userName"]);
        $.cookie("username",data["userName"]);
      },
      error: function (data) {
        console.log(data)
      }
    });


  }
  ///menu/list
  function get_menu_list(){

    $.ajax({
      url: host_proc+"/menu/list",
      type: 'GET',
      headers: {
        "token": token
      },
      success: function (data) {
        template_tail = "</dl></li>";
        $.each(data["menuList"],function(k,v){
          template_head="<li class=\"layui-nav-item layui-nav-itemed\"><a class=\"\" href=\"javascript:;\" id=\"getMenu\">"+
                  k+"</a><dl class=\"layui-nav-child\">"
          ary = v.substring(0,v.length-1).split(",")
          content = ""
          $.each(ary,function (i,ary){
            content+="<dd><a href=\"\">"+ary+"</a></dd>"
          })
          $("#menuid").append(template_head+content+template_tail);

        })

      },
      error: function (data) {
        console.log(data)
      }
    });

  }

  //JS
  layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

    //头部事件
    util.event('lay-header-event', {
      //左侧菜单事件
      menuLeft: function(othis){
        layer.msg('展开左侧菜单的操作', {icon: 0});
      }
      ,menuRight: function(){
        layer.open({
          type: 1
          ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
          ,area: ['260px', '100%']
          ,offset: 'rt' //右上角
          ,anim: 5
          ,shadeClose: true
        });
      }
    });

    $(document).ready(function(){
      token = $.cookie("access_token");
      //system_client_grant()
      get_user_info()
      get_menu_list()
    });

    element.init();

  });

</script>
